package team.unstudio.unknownrpg_base.config;

import java.util.Map;
import java.util.Map.Entry;

import indi.defoliation.unknownrpg.api.attribute.Attribute;
import indi.defoliation.unknownrpg.api.config.YamlConfigurer;
import team.unstudio.unknownrpg_base.UnknownRPGBase;

public class AttributeConfigManager {
	
	private static YamlConfigurer config;
	
	public static void init() {
		config = new YamlConfigurer(UnknownRPGBase.getInstance(),"AttributeConfig.yml");
	}
	
	public static void registeAttribute(Attribute att,Map<String,Object> map) {
		for(Entry<String,Object> entry : map.entrySet()) {
			if(config.contains(getKey(att,entry.getKey())))continue;
			config.set(getKey(att,entry.getKey()), entry.getValue());
		}
	}
	
	private static String getKey(Attribute att,String key) {
		return att.getKeyName()+"."+key;
	}
	
	public static void save() {
		config.save();
	}
	
	public static <T> T get(Attribute att,String key) {
		return config.getValue(getKey(att,key));
	}
	
	public static void reload() {
		config.reload();
	}
}
